package com.hainatong.shiphelper.login.view;


import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.base.common.utils.LanguageManageUtil;
import com.base.common.view.adapter.bean.HeaderBean;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.base.BaseFragment;
import com.base.common.viewmodel.BaseViewModel;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.FragmentListViewBinding;
import com.hainatong.shiphelper.login.adapter.LanguageAdapter;
import com.hainatong.shiphelper.login.model.LanguageBean;

import java.util.ArrayList;
import java.util.List;

public class LanguageFragment extends BaseFragment<FragmentListViewBinding, BaseViewModel> {

    @Override
    protected FragmentListViewBinding initDataBinding(LayoutInflater inflater, ViewGroup container) {
        return DataBindingUtil.inflate(inflater, R.layout.fragment_list_view, container, false);
    }

    private LanguageAdapter adapter;
    private List<LanguageBean> languageModels;

    @Override
    public void initView() {
        adapter = new LanguageAdapter();
        languageModels = new ArrayList<>();
        binding.recyclerview.setHasFixedSize(true);
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter.addHeaderView(new HeaderBean(BaseItemMultiType.TYPE_HEAD));
        adapter.setRadio(true);
        binding.recyclerview.setAdapter(adapter);
    }

    @Override
    public void initData() {
        super.initData();

        LanguageBean zh = new LanguageBean();
        zh.setLanguage("中文（默认）");
        zh.setLanguageType("zh/中文");
        zh.setLocalType(LanguageManageUtil.LOCAL_CHINA);
        languageModels.add(zh);

        LanguageBean en = new LanguageBean();
        en.setLanguage("英文");
        en.setLanguageType("English/英文");
        en.setLocalType(LanguageManageUtil.LOCAL_ENGLISH);
        languageModels.add(en);


        int languageType = LanguageManageUtil.getCurrentLanguageType();

        for (LanguageBean languageModel : languageModels) {
            if (languageModel.getLocalType() == languageType) {
                languageModel.setSelected(true);
            } else {
                languageModel.setSelected(false);
            }
        }

        adapter.setDataList(languageModels);
    }


}
